//index.js
//获取应用实例
const db = wx.cloud.database();
const app = getApp();
const list = db.collection('goods');
Page({
  data: {
    cultures: [],
    product: undefined,
    active: 0,
    cardCur: 0,
    TabCur: 0,
    scrollLeft: 0,
    swiperList: [{
      id: 0,
      type: 'activity',
      url: 'https://ss2.bdstatic.com/70cFvnSh_Q1YnxGkpoWK1HF6hhy/it/u=3495934836,1077404850&fm=26&gp=0.jpg'
    }, {
      id: 1,
      type: 'activity',
      url: 'https://img.zcool.cn/community/01e03357aea3bb0000012e7e27e68f.jpg@1280w_1l_2o_100sh.jpg',
    }, {
      id: 2,
      type: 'activity',
      url: 'http://image.xinmin.cn/xmwb/2016/4/NEM1_20160423_C032462446_A139519.jpg'
    }, {
      id: 3,
      type: 'activity',
      url: 'http://image.xinmin.cn/xmwb/2016/4/NEM1_20160423_C032462446_A139518.jpg'
    }, {
      id: 4,
      type: 'activity',
      url: 'https://img.zcool.cn/community/01bba357aea3c00000018c1b2ebe59.jpg@1280w_1l_2o_100sh.jpg'
    }, {
      id: 5,
      type: 'activity',
      url: 'https://img.zcool.cn/community/01d64157aea3c30000012e7eea923b.jpg@1280w_1l_2o_100sh.jpg'
    }, {
      id: 6,
      type: 'activity',
      url: 'https://img.zcool.cn/community/01958b57aea3c60000018c1b0297b0.jpg@1280w_1l_2o_100sh.jpg'
    }],
    tabList: [{
      id: 0,
      name: '发现'
    }, {
      id: 1,
      name: '直播'
    }, {
      id: 2,
      name: '商城'
    }],
    titleList: [{
      id: 0,
      name: "推荐",
      type: "reco",
      list: []
    }, {
      id: 1,
      name: '万物可盘',
      type: "wamwu",
      list: []
    }, {
      id: 2,
      name: "木作盘玩",
      type: "mu",
      list: []
    }, {
      id: 3,
      name: "玉石",
      type: "yushi",
      list: []
    }, {
      id: 4,
      name: "文玩",
      type: "wenwan",
      list: []
    }],
    sellList: [{
      id: 0,
      name: '0元拍',
      url: 'like'
    },
    {
      id: 1,
      name: '专场拍',
      url: 'friends'
    },
    {
      id: 2,
      name: '直播拍',
      url: 'video'
    },
    {
      id: 3,
      name: '历史拍品',
      url: 'star'
    }
    ],
    aucationList: [{
      id: 0,
      text: '故宫文化 海错图书本灯有线款书页灯卧室小夜灯创意礼物文创礼品',
      url: 'https://img13.360buyimg.com/n7/jfs/t1/36856/25/3043/466627/5cb73a2fE45659fda/82292258b973df34.jpg'
    },
    {
      id: 1,
      text: '故宫文化 云起龙襄纸砖笔记本 办公用品文具 文创创意礼品 生日纪念日礼物礼品 云起龙襄纸砖',
      url: 'https://img14.360buyimg.com/n7/jfs/t1/131686/31/17701/170274/5fc3cdbeEbfffdbf1/364849f61110aae2.jpg'
    },
    {
      id: 2,
      text: '中国国家博物馆斗转星移有线小夜灯卧室中国风创意礼品led灯博物馆文创台灯国博',
      url: 'https://img12.360buyimg.com/n7/jfs/t1/147787/36/16126/425674/5fc3c5ebEce33f43b/92ea07b232876bad.jpg'
    }
    ]
  },
  toSearch: function () {
    wx.navigateTo({
      url: '/pages/search/search'
    })
  },
  tabSelect: function (e) {
    this.setData({
      TabCur: e.currentTarget.dataset.id,
      scrollLeft: (e.currentTarget.dataset.id - 1) * 60
    })
    if(this.data.TabCur == 1)
    {
      wx.navigateToMiniProgram({
        appId:'wx74767bf0b684f7d3',
        path: 'pages/subPages/search/index.html'
      })
    }
  },
  toAucation: function (e) {
    const page = e.currentTarget.dataset.page;
    if (page == 0) {
      wx.navigateTo({
        url: '/pages/zero/zero',
      })
    } else if (page == 1) {
      wx.navigateTo({
        url: '/pages/zero/zero',
      })
    } else if (page == 2) {
      wx.navigateTo({
        url: '/pages/zero/zero',
      })
    } else if (page == 3) {
      console.log(page);
      wx.navigateTo({
        url: '/pages/zero/zero',
      })
    }
  },
  onChange: function (event) {
    const _this = this;
    wx.cloud.callFunction({
      name: "getGoods",
      data: {
        index: event.detail.index
      }
    }).then(res => {
      console.log(res)
      for(var i = 0 ; i < 5 ; i ++){
        if(event.detail.index == i){
          let str = 'titleList['+i+'].list'
          _this.setData({
            [str]: res.result.data
          })
        }
      }  
    })
  },
  onLoad: async function (options) {
    console.log(this.openid = await getApp().getOpenid())
    wx.cloud.callFunction({
      name: 'getAllCulture'
    }).then(res => {
      console.log(res)
      this.setData({
        cultures: res.result.data
      })
      console.log(this.data.cultures)
    })
  },
  onReady: function()
  {
    this.product = this.selectComponent('#product')
  },
  toHuya: function(){
    if(this.data.TabCur === 1)
    {
      wx.navigateToMiniProgram({
        appId:'wx74767bf0b684f7d3',
        path: 'pages/subPages/search/index.html'
      })
    }
  }
})